package com.spica.platform.base.feign;

import com.spica.platform.base.config.BaseFeignConfig;
import com.spica.platform.base.feign.fallback.AsyncUserFeignClientFallbackFactory;
import com.spica.platform.base.model.LoginAppUser;
import com.spica.platform.base.model.ResponseEntity;
import com.spica.platform.base.model.SysUser;
import com.spica.platform.common.constant.ServiceNameConstant;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import reactivefeign.spring.config.ReactiveFeignClient;
import reactor.core.publisher.Mono;

/**
* 调用用户中心中的userdetail对象，用户oauth中的登录
* 获取的用户与页面输入的密码 进行BCryptPasswordEncoder匹配
 */
@ReactiveFeignClient(name = ServiceNameConstant.USER_SERVICE,configuration = BaseFeignConfig.class , fallbackFactory = AsyncUserFeignClientFallbackFactory.class, decode404 = true)
public interface AsyncUserFeignClient {
    /**
     * feign rpc访问远程/users/{username}接口
     * 查询用户实体对象SysUser
     */
    @GetMapping(value = "/users/username", params = "username")
    Mono<ResponseEntity<SysUser>> findSysUserByUsername(@RequestParam("username") String username);

    /**
     * feign rpc访问远程/users-anon/userId接口
     * 参数在header的params中
     * 根据userId查询用户信息LoginAppUser
     */
    @GetMapping(value = "/users-anon/userId", params = "userId")
    Mono<ResponseEntity<LoginAppUser>> findLoginAppUserByUserId(@RequestParam("userId")  String userId);

    /**
     * feign rpc访问远程/users-anon/username接口
     * 参数在header的params中
     * 通过用户名查询用户、角色信息LoginAppUser
     */
    @GetMapping(value = "/users-anon/username", params = "username")
    Mono<ResponseEntity<LoginAppUser>> findLoginAppUserByUsername(@RequestParam("username") String username);

    /**
     * feign rpc访问远程/users-anno/mobile接口
     * 通过手机号查询用户、角色信息
     * 参数在header的params中
     * 通过手机号查询LoginAppUser
     */
    @GetMapping(value = "/users-anon/mobile", params = "mobile")
    Mono<ResponseEntity<LoginAppUser>> findLoginAppUserByMobile(@RequestParam("mobile") String mobile);

    /**
     * feign rpc访问远程/users-anon/openId接口
     * 根据OpenId查询用户信息
     * 参数在header的params中
     * 通过openId查询LoginAppUser
     */
    @GetMapping(value = "/users-anon/openId", params = "openId")
    Mono<ResponseEntity<LoginAppUser>> findLoginAppUserByOpenId(@RequestParam("openId") String openId);
}
